package com.project.weather.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.project.weather.dao.RoleMapper;
import com.project.weather.pojo.RoleBean;
import com.project.weather.service.RoleService;
import com.project.weather.common.PageBean;
import com.project.weather.common.AResultCode;
import com.project.weather.common.ResultMap;
import com.project.weather.utils.StringUtil;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *<p>Title:RoleServiceImpl.java</p>
 *<p>Description:角色信息表ServiceImpl</p>
 *@author xxx
 *@version 1.0
 *@Automatically generate by Coder in 2021-12-21 16:07
 */
@Service
public class RoleServiceImpl implements RoleService{
	private static final Logger log = LoggerFactory.getLogger(RoleServiceImpl.class);
	@Autowired
	private RoleMapper roleMapper;
	
	@Override
	public ResultMap<AResultCode, RoleBean> insert(RoleBean bean){
		ResultMap<AResultCode, RoleBean> result = new ResultMap<AResultCode, RoleBean>();
		if(StringUtil.isNull(bean)){
			result.setCode(AResultCode.IS_NULL);
		} else {
//			if(StringUtil.isNull(bean.getRole_id())){
//				bean.setRole_id(StringUtil.getUUID());
//			}
			roleMapper.insertSelective(bean);	
			result.setCode(AResultCode.OK);
			result.setResult(bean);
		}
		return result;
	}

	
	@Override
	public ResultMap<AResultCode, RoleBean> update(RoleBean bean){
		ResultMap<AResultCode, RoleBean> result = new ResultMap<AResultCode, RoleBean>();

		if(StringUtil.isNull(bean)){
			result.setCode(AResultCode.IS_NULL);
		} else if(StringUtil.isNull(bean.getRole_id())){
			result.setCode(AResultCode.MISS_ID);
		} else {
			roleMapper.updateSelective(bean);	
			result.setCode(AResultCode.OK);
			result.setResult(bean);
		}

		return result;
	}

	
	@Override
	public ResultMap<AResultCode, RoleBean> delete(String role_id){
		ResultMap<AResultCode, RoleBean> result = new ResultMap<AResultCode, RoleBean>();

		if(StringUtil.isNull(role_id)){
			result.setCode(AResultCode.MISS_ID);
		} else {
			String[] ids = role_id.split(",");
			roleMapper.delete(ids);
			result.setCode(AResultCode.OK);
		}

		return result;
	}

	
	@Override
	public ResultMap<AResultCode, PageBean<RoleBean>> pageList(PageBean<RoleBean> pb){
		ResultMap<AResultCode, PageBean<RoleBean>> result = new ResultMap<AResultCode, PageBean<RoleBean>>();

		pb.setData(roleMapper.pageList(pb));
		pb.clear();

		result.setCode(AResultCode.OK);
		result.setResult(pb);

		return result;
	}

	
	@Override
	public ResultMap<AResultCode, List<RoleBean>> list(RoleBean bean){
		ResultMap<AResultCode, List<RoleBean>> result = new ResultMap<AResultCode, List<RoleBean>>();

		List<RoleBean> list = roleMapper.list(bean);
		result.setCode(AResultCode.OK);
		result.setResult(list);

		return result;
	}

	
	@Override
	public ResultMap<AResultCode, RoleBean> get(String role_id){
		ResultMap<AResultCode, RoleBean> result = new ResultMap<AResultCode, RoleBean>();
		if(StringUtil.isNull(role_id)){
			result.setCode(AResultCode.MISS_ID);
		} else {
			RoleBean bean = roleMapper.get(role_id);
			if(bean != null) {
				result.setCode(AResultCode.OK);
				result.setResult(bean);
			} else {
				result.setCode(AResultCode.UNEXIST);
	 		}
		}
		return result;
	}

	
}